<?php
namespace app\repair\validate;
use app\validate\Common;
use think\Validate;
use think\Db;
class Fault extends Common
{
	/*验证规则*/
	protected $rule = [
		'type'			=> 'require|in:0,1,2,3,4',
		'describes'		=> 'require|describes',
	];
	/*验证提示信息*/
	protected $message = [
		'describes.require'		=> '描述不能为空',
		'describes.describes'	=> '描述已存在',
		'type.require'			=> '类型不能为空',
		'type.in'				=> '类型格式错误',
	];
	/*验证场景*/
	protected $scene = [
		'add'	=> ['describes','type'],
	];

	/**
	 * 自定义方法
	 */
	protected function describes($value, $rule, $data)
	{
		$where = [];
		if(isset($data['ids'])){
			$where['fault_id'] = ['neq',$data['ids']];
		}
		$count = Db::name('fault')
		->where('describes',$value)
		->where($where)
		->where('type',$data['type'])
		->count();
		return $count > 0 ? false : true;
	}
}